﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BOHVote.BLL;
 
using System.Data;
using BOHVote.Entity;

namespace BOH.DataManagement
{
    public partial class ModifyInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["ID"] != null)
                {
                    FillForm(Request.QueryString["ID"].ToString());
                }
            }
        }

        public void FillForm(string NotifyID)
        {
            DataSet dst = NotifyClass.getNotifyByID(NotifyID);
            if (dst.Tables.Count > 0 && dst.Tables[0].Rows.Count > 0)
            {
                txtInfoTitle.Text = dst.Tables[0].Rows[0]["Notify_title"].ToString();
                drpStatus.SelectedValue = dst.Tables[0].Rows[0]["Notify_status"].ToString();
                drpVerify.SelectedValue = dst.Tables[0].Rows[0]["Notify_Verify"].ToString();
                txtInofContext.Value = dst.Tables[0].Rows[0]["Notify_Context"].ToString();
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["ID"] != null)
            {
                UpdateNotify(Request.QueryString["ID"].ToString());
            }
            else
            {
                SaveNotify();
            }
        }

        public void UpdateNotify(string NotifyID)
        {
            if (Session["user"] != null)
            {
                int returnValue = NotifyClass.UpdateNotify(NotifyID,this.txtInfoTitle.Text, drpVerify.SelectedValue, drpStatus.SelectedValue, txtInofContext.Value, ((BHUser)Session["user"]).UserID);
                if (returnValue > 0)
                {
                    Response.Redirect("ApplyInfoManage.aspx");
                }
                else
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "confirm", "<script>alert('数据保存不成功');</script>");
                }
            }
        }

        public void SaveNotify()
        {
            if (Session["user"] != null)
            {
                int returnValue = NotifyClass.InsertNotify(this.txtInfoTitle.Text, drpVerify.SelectedValue, drpStatus.SelectedValue, txtInofContext.Value,((BHUser)Session["user"]).UserID);
                if (returnValue > 0)
                {
                    Response.Redirect("ApplyInfoManage.aspx");
                }
                else
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "confirm", "<script>alert('数据保存不成功');</script>");
                }
            }
        }


    }
}
